<html>
<head><meta charset="utf-8"><title>how to get DefId of &#x27;Send&#x27; trait · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html">how to get DefId of &#x27;Send&#x27; trait</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212716844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212716844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212716844">(Oct 08 2020 at 16:37)</a>:</h4>
<p>Hello <span aria-label="crab" class="emoji emoji-1f980" role="img" title="crab">:crab:</span>  I'm writing a simple static checker using the Rustc API, and I'd really appreciate advice on how I can fetch the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html"><code>DefID</code></a> of the <code>Send</code> trait!  While it was easy to fetch the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html"><code>DefID</code></a> of the <code>Sync</code> trait by doing <code>tcx.lang_items().sync_trait()</code>, it seems that <code>Send</code> is not included in the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/lang_items/enum.LangItem.html"><code>LangItem</code></a> enum and thus  struct<code>LanguageItems</code> doesn't provide an API like <code>send_trait()</code> <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span></p>



<a name="212717094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212717094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212717094">(Oct 08 2020 at 16:39)</a>:</h4>
<p>not all traits are lang items</p>



<a name="212717100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212717100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212717100">(Oct 08 2020 at 16:39)</a>:</h4>
<p>what are you trying to do?</p>



<a name="212717452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212717452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212717452">(Oct 08 2020 at 16:42)</a>:</h4>
<p>I was trying to make my simple checker inspect all implementations of <code>Send</code> and <code>Sync</code> given an input program.<br>
Currently it can locate all implementations of the <code>Sync</code> trait, but it currently doesn't know how to catch implementations of the <code>Send</code> trait.</p>



<a name="212717910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212717910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212717910">(Oct 08 2020 at 16:45)</a>:</h4>
<p>The description for <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/lang_items/index.html">module <code>rustc_hir::lang_items</code></a> mentions <code>Send</code> trait to be an example of a language item, but yet <code>Send</code> is not included in the <code>LangItem</code> enum.</p>



<a name="212718113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718113">(Oct 08 2020 at 16:47)</a>:</h4>
<p>it's probably just out of date docs</p>



<a name="212718160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718160">(Oct 08 2020 at 16:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="242132">JOE1994</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/how.20to.20get.20DefId.20of.20'Send'.20trait/near/212717452">said</a>:</p>
<blockquote>
<p>I was trying to make my simple checker inspect all implementations of <code>Send</code> and <code>Sync</code> given an input program.<br>
Currently it can locate all implementations of the <code>Sync</code> trait, but it currently doesn't know how to catch implementations of the <code>Send</code> trait.</p>
</blockquote>
<p>you could look for the <code>core::marker::Send</code> defpath maybe</p>



<a name="212718213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718213">(Oct 08 2020 at 16:47)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> does things like this but I think his approach is usually to make items <code>rustc_diagnostic_items</code> to avoid being confused by imports renaming things</p>



<a name="212718421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718421">(Oct 08 2020 at 16:49)</a>:</h4>
<p><code>tcx.diagnostic_items().get(sym::send_trait)</code> would work in this case</p>



<a name="212718436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718436">(Oct 08 2020 at 16:49)</a>:</h4>
<p><code>lang_items</code> work almost the same way as <code>rustc_diagnostic_item</code> iirc. Send not being included is probably just an oversight</p>



<a name="212718531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718531">(Oct 08 2020 at 16:50)</a>:</h4>
<p>But using that will let you start using it immediately and not have to wait until a new release includes the diagnostic item</p>



<a name="212718550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212718550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212718550">(Oct 08 2020 at 16:50)</a>:</h4>
<p>*lang item</p>



<a name="212719696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212719696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212719696">(Oct 08 2020 at 16:58)</a>:</h4>
<p>IMO things shouldn't be lang items unless they need to be</p>



<a name="212719740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212719740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212719740">(Oct 08 2020 at 16:58)</a>:</h4>
<p>It's more work in rustdoc's end trying to keep everything up to date</p>



<a name="212722439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20get%20DefId%20of%20%27Send%27%20trait/near/212722439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20get.20DefId.20of.20&#x27;Send&#x27;.20trait.html#212722439">(Oct 08 2020 at 17:19)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span>  <span class="user-mention" data-user-id="116107">@davidtwco</span>  <span class="user-mention" data-user-id="119031">@Esteban Küber</span> <br>
Thank you all for your help! <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span>  <code>tcx.diagnostic_items().get(sym::send_trait)</code> worked well for me :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>